package antrace;

import processing.core.PMIDlet;

public class MenuView extends Overlay implements InterfaceView {
	
	public HighscoreOverlay highscore;
	
	private int numberOfItems = 3;

	public MenuView() {

		super(AntRace.midlet.loadImage("/images/menu/menuBG.png"));

		texts = new OverlayText[numberOfItems];
		texts[0] = new OverlayText("Play game", 55, 127, AntRace.whiteFont);
		texts[1] = new OverlayText("Highscores", 45, 172, AntRace.whiteFont);
		texts[2] = new OverlayText("Exit game", 55, 217, AntRace.whiteFont);

		highscore = new HighscoreOverlay();
		
		this.updateSelects();
	}

	public void draw() {
		if(highscore.isVisible()){
			highscore.draw();
		}
		else{
			super.draw();
		}		
	}

	public void keyPressed(int keyCode) {
		if(highscore.isVisible())
			highscore.keyPressed(keyCode);
		else{
			switch (keyCode) {
			case PMIDlet.UP:
				if(selectedIndex == 0)
					selectedIndex = 2;
				else
					selectedIndex--;
				break;
			case PMIDlet.DOWN:
				if(selectedIndex == numberOfItems-1)
					selectedIndex = 0;
				else
					selectedIndex++;
				break;	
			case PMIDlet.FIRE:
				switch(selectedIndex){
				case 0:
					AntRace.viewManager.currentView = AntRace.game;
					AntRace.game.resetGame();
					break;
				case 1:
					highscore.toggleVisible();
					break;
				case 2:
					AntRace.viewManager.quit();
					break;
				}
				break;
			}
			this.updateSelects();
		}
	}

	public void keyReleased(int keyCode) {
		// TODO Här görs inget just nu
	}

}